
//引入获取商品的请求方法
import * as api from "@/api"


export default {
    namespaced:true,
    state:{
        productData:[]
    },
    mutations:{
        //更改productData的mutation
        SET_PT_DATA(state,payload){
            state.productData = payload
        },
        DE_IY(state,payload){
            let target = state.productData.find(item => item.id=== payload)
            if(target){
                target.inventory--
            }

            if(target.count===0){
                state.catrs = state.catrs.filter(item=>item.id!==target.id)
            }
        },
        IE_IY(state,payload){
            let target = state.productData.find(item => item.id=== payload.id)
            if(target){
                target.inventory++
            }
        },
        
    },
    actions:{
        //使用action获取异步数据
        async FH_PT(context){
             let res = await api.fetchProduct()
             console.log(res)
             context.commit('SET_PT_DATA',res.data)
        }
    },
    getters:{}
}